package com.igroupes.ovineherd.controller;

import com.igroupes.ovineherd.util.MagicNumberCheck;
import com.igroupes.ovineherd.util.Requires;
import com.igroupes.ovineherd.vo.ResultVO;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("cache")
public class CacheController {

    @RequestMapping("deleteOne")
    @CacheEvict(value = "#cache", key = "#key")
    public ResultVO deleteOne(String cache, String key, String code) {
        Requires.requireNonNull(cache, "cache is null");
        Requires.requireNonBlank(code, "magic number is null");
        Requires.requireNonBlank(key, "key is null");
        MagicNumberCheck.check(MagicNumberCheck.CheckType.Cache, code);
        return ResultVO.success();
    }

    @RequestMapping("deleteAll")
    @CacheEvict(value = "#cache", allEntries = true)
    public ResultVO deleteAll(String cache, String code) {
        Requires.requireNonNull(cache, "cache is null");
        Requires.requireNonBlank(code, "magic number is null");
        MagicNumberCheck.check(MagicNumberCheck.CheckType.Cache, code);
        return ResultVO.success();
    }


}
